package com.kemai.common.ui

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.MotionEvent
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.kemai.common.R
import com.kemai.common.adapter.ItemClickListener
import com.kemai.common.adapter.StudyContentAdapter
import java.lang.Exception

/**

 *@description:TODO
 * @author: zhaoshanshan
 * @date: 2022/10/1 6:05 下午

 */
open class BaseActivity : AppCompatActivity(),View.OnClickListener,View.OnTouchListener{
    private  lateinit var  rvCommonContent: RecyclerView
    private lateinit var  title: TextView
    private lateinit var  back: TextView
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.hide()
    }

    override fun setContentView(layoutResID: Int) {
        super.setContentView(layoutResID)
        findViewById()
    }
    open fun findViewById(){

        try {
            title = findViewById(R.id.title)
            back = findViewById(R.id.back)
            rvCommonContent = findViewById(R.id.rv_common_content)

        }catch (e:Exception){
            e.printStackTrace()
        }finally {
            back.setOnClickListener(this)
        }

    }
    open fun setTiTle(titleContent:String){
        title.text = titleContent;
    }

    override fun onClick(v: View?) {
        when(v?.id){
            R.id.back->{
                finish()
            }
        }
    }
    fun<T> showPage(context: Context, cls:Class<T> ){
        val intent = Intent(context,cls)
        startActivity(intent)
    }

     fun setAdapterContent(array:Array<String>,context:Context,itemClickListener: ItemClickListener){
         if(null==array|| array.isEmpty()){
             return
         }
         val linearLayoutManager  = LinearLayoutManager(this)
         rvCommonContent.layoutManager = linearLayoutManager
         val studyContentAdapter = StudyContentAdapter(array,context,itemClickListener)
         rvCommonContent.adapter = studyContentAdapter
    }

    open fun setOnClickListener(){

    }
    open fun setOnTouchListener(){

    }
    open fun init(){

    }

    override fun onTouch(v: View?, event: MotionEvent?): Boolean {
        return false
    }

}